package com.yc.springboot.web;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class YmlAction {

    //@Value(" SpEL Spring 表达式 ==> OGNL 表达式 ")
    @Value("${demo.name}")
    private String name;
    @Value("${demo.age}")
    private int age;
//    @Value("${demo.familys}")
//    private Map<String,Object> familys;

    @Resource
    private Person person;

    @GetMapping("getName")
    String getName(){
        return name;
    }

    @GetMapping("getAge")
    int getAge(){
        return age;
    }

//    @GetMapping("familys")
//    Map<String,Object> familys(){
//        return familys;
//    }

    @GetMapping("person")
    Person person(){
        return person;
    }

}

@Data
@Component
@ConfigurationProperties(prefix = "demo")
class Person{
    String name;
    int age;
    String[] likes;
    List<String> schools;
    List<Map<String,Object>> friends;
    Map<String,Object> familys;
    List<Dog> dogs;
}

@Data
class Dog{
    String name;
    int age;
}